<?php

class Login_Model extends Model{
	
	private $id_user;
	private $name_user;
	private $email_user;
	private $pass_user;
	
	private $sqlSelect = "SELECT * FROM user WHERE 1=1 %s %s";
	
	public function setIdUser($id_user){
		$this->id_user = trim(strip_tags($id_user));
	}
	
	public function setNameUser($name_user){
		$this->name_user = trim(strip_tags($name_user));
	}
	
	public function setEmailUser($email_user){
		$this->email_user = trim(strip_tags($email_user));
	}
	
	public function setPassUser($pass_user){
		$pass = trim(strip_tags($pass_user));
		$this->pass_user = md5($pass);
	}
	
	public function getIdUser(){
		return $this->id_user;	
	}
	
	public function getNameUser(){
		return $this->name_user;	
	}
	
	public function getEmailUser(){
		return $this->email_user;	
	}
	
	public function getPassUser(){
		return $this->pass_user;	
	}
	
	public function select($where='',$order=''){
		$sql = sprintf($this->sqlSelect,$where,$order);
		return $this->runSelect($sql);	
	}
	
	public function selectEntrar($where='',$order=''){
		$sql = sprintf($this->sqlSelect,$where,$order);
		return $this->runEntrar($sql);	
	}
	
	public function load(){
		$where = sprintf("AND email_user='%s' AND pass_user='%s'",$this->getEmailUser(),$this->getPassUser());
		$row = $this->select($where);
		$this->setIdUser($row[0]['id_user']);
		$this->setNameUser($row[0]['name_user']);
		$this->setEmailUser($row[0]['email_user']);
		$this->setPassUser($row[0]['pass_user']);
		return $this;						
	}
	
	public function loadEntrar(){
		$where = sprintf("AND email_user='%s' AND pass_user='%s'",$this->getEmailUser(),$this->getPassUser());
		return $this->selectEntrar($where);						
	}
}

?>
	